package com.nbcp

import nbcp.MainApplication
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.support.GenericXmlApplicationContext
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.context.web.WebAppConfiguration
import org.springframework.test.web.servlet.MockMvc
import nbcp.base.utils.CodeUtil
import org.junit.Test
import org.springframework.boot.SpringBootConfiguration
import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureMockRestServiceServer
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.util.LinkedMultiValueMap


/**
 * Created by udi on 17-3-27.
 */


@RunWith(SpringRunner::class)
//@WebAppConfiguration
@AutoConfigureMockMvc
@SpringBootTest(classes = arrayOf(MainApplication::class), webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = arrayOf("classpath:application.yml","classpath:application-win.yml"))
//@ActiveProfiles("unittest","productprofile")
class TestBase {
    @Autowired
    lateinit var mvc: MockMvc

  /*  init {
        GenericXmlApplicationContext().environment.setActiveProfiles("test")
        //ParserConfig.getGlobalInstance().putDeserializer(ObjectId::class.java, ObjectIdDeserializer())
    }*/

    init {
        GenericXmlApplicationContext().environment.setActiveProfiles("test")
        System.setProperty("server.dbIp", "lzh");
        System.setProperty("shop.scheduler","false")
        System.setProperty("shop.mq.consumer","false")
        //ParserConfig.getGlobalInstance().putDeserializer(ObjectId::class.java, ObjectIdDeserializer())
    }


//    @Autowired
//    lateinit var  restTemplate: TestRestTemplate
//
//    @Test
//    fun test2() {
//        val params = LinkedMultiValueMap<Any, Any>()
//        params.add("grant_type", "client_credentials")
//        val response = restTemplate.withBasicAuth("clientId", "clientSecret")
//                .postForObject("/oauth/token", params, String::class.java)
//        println(response)
//    }
}